<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
<style>
    body{
        margin: 0;
        background-image: url("img/2.png");
        background-size: cover;
        text-align: center;
    }
    h1{
        font-size: 72px;
        margin-bottom: 0;
    }
    h2{
        font-size: 32px;
        margin-bottom: 0;
    }
</style>
</head>
<body>
<div id="app">
    <h1>欢迎来到黑马教育</h1>
    <h2>BLACK horse</h2>
    <el-card style="width:600px;height: 300px;margin: 0 auto;
background-color: rgba(30,144,255,0.3)">
<el-form label-width="60px" style="width: 400px; margin: 40px auto;position: relative;right: 30px" >
    <el-form-item label="用户名">
        <el-input type="text" v-model="user.username" placeholder="请输入用户名"></el-input>
    </el-form-item>
    <el-form-item label="密码">
        <el-input type="password" v-model="user.password" placeholder="请输入密码"></el-input>
    </el-form-item>
    <el-form-item>
        <el-checkbox v-model="user.rem">记住用户名和密码</el-checkbox>
    </el-form-item>
    <el-form-item>
        <el-button  type="primary" @click="login()">登录</el-button>
    </el-form-item>
</el-form>
    </el-card>

</div>
</body>
<!--引入Axios框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
   let v = new Vue({
        el: '#app',
        data: function() {
            return {
                user:{
                    username:"",
                    password:"",
                    rem:false
                }

            }
        },
       methods:{
            login(){
                axios.post("/login",v.user).then(function (response) {
                    if(response.data==1){
                        location.href="/admin.html";
                    }else if(response.data==2){
                        v.$message("密码错误!")
                    }else{
                        v.$message("登陆错误!")
                    }
                })
            }
       },
       created:function () {
            /*'username=admin; password=123456'*/
           let arr = document.cookie.split(";");
           for(let cookie of arr){
               let cookieArr = cookie.split("=");
               let key = cookie[0].trim();
               let value = cookieArr[1]
               if(key=="username"){
                   this.user.username=value;
               }
               if(key=="password"){
                   this.user.password=value;
               }
           }
       }

    })
</script>
</html>